//
//  MainTabBar.m
//  weibo_oc
//
//  Created by 岳挺 on 15/6/25.
//  Copyright © 2015年 yueting. All rights reserved.
//

#import "MainTabBar.h"
#define kBtnCount 5

@interface MainTabBar()

@end

@implementation MainTabBar

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat w = self.bounds.size.width / kBtnCount;
    CGRect rect = CGRectMake(0, 0, w, self.bounds.size.height);
    int index = 0;
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UIControl class]] && ![view isKindOfClass:[UIButton class]]) {
            view.frame = CGRectOffset(rect, index * w, 0);
            index += index == 1 ? 2 : 1;
        }
    }
    
    self.composeBtn.frame = CGRectOffset(rect, 2 * w, 0);
    
}

- (UIButton *)composeBtn
{
    if (_composeBtn == nil) {
        UIButton *btn = [[UIButton alloc] init];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [self addSubview:btn];
        _composeBtn = btn;
    }
    return _composeBtn;
}

@end
